package store

import (
	"gorm.io/gorm"
	"guard/internal/app/admin/models"
	"guard/internal/tool"
)

type AdminStore interface {

	/**
	客户端信息管理
	*/

	SelClientPage(current, size int) *tool.Paginator
	SelClientQuery(id string, clientName string) (mc *models.ClientInfo, err error)
	SaveClient(info models.ClientInfo) error
	UpdateClient(info models.ClientInfo) error
	DelClient(id string) error

	/**
	客户端范围权限管理
	*/

	SelScopeAll() (mas []models.AuthorityScope, err error)
	SelScopePage(current, size int) *tool.Paginator
	SelScopeQuery(tag, permission string) (as *models.AuthorityScope, err error)
	SaveOrUpdateScope(scope models.AuthorityScope) error
	DelScope(tag string) error

	/**
	用户app管理
	*/

	SelUserApp(username string) (mu []models.UserApp, err error)
	SelUserAppCount(username string) (count int, err error)
	SaveUserApp(app models.UserApp) error
	DelUserApp(username, cid string) error
}

type adminStoreImpl struct {
	db *gorm.DB
}

func NewAdminStore(d *gorm.DB) AdminStore {
	return &adminStoreImpl{
		db: d,
	}
}
